﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using models;
using System.Data.SqlClient;




namespace DAL
{
    public class userService
    {
        //用户表操作
        //查询用户信息
        public SqlDataReader selectUser()
        {
            string sql = string.Format("select * from [User]");
            return DBhelper.DataReader(sql);
        }
        //根据id查询
        public SqlDataReader selectUserid(int id)
        {
            string sql = string.Format("select * from [User] where id='{0}'",id);
            return DBhelper.DataReader(sql);
        }
        //修改用户信息
        public bool updataUser(User user,string id)
        {
            string sql = string.Format("update [User] set UName='{0}',Sex='{1}',Birthday='{2}',Phone='{3}',Email='{4}' where Id='{5}'",user.UName,user.Sex,user.Birthday,user.Phone,user.Email,id);
            return DBhelper.ex(sql);           
        }
        //修改安全设置登录密码
        public bool updatapassword(User user)
        {
            string sql = string.Format("update [User] set Pwd='{0}' where Id='{1}'", user.Pwd, user.Id);
            return DBhelper.ex(sql);
        }
        //修改安全设置手机验证
        public bool updataphone(User user)
        {
            string sql = string.Format("update [User] set Phone='{0}' where Id='{1}'",user.Phone,user.Id);
            return DBhelper.ex(sql);
        }
        //修改安全设置邮箱验证
        public bool updataemail(User user)
        {
            string sql = string.Format("update [User] set Email='{0}' where Id='{1}'",user.Email, user.Id);
            return DBhelper.ex(sql);
        }
     

        public bool Adduser(User user)
        {
            /// <summary>
            /// 新增用户信息
            /// </summary>
            string sql = string.Format("insert [user] values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", user.Uid, user.Pwd, user.UName, user.Sex, user.Birthday, user.Phone, user.Email);
            return DBhelper.ex(sql);
        }
        //根据账号密码查询用户
        public SqlDataReader dl(string uid,string pwd)
        {
            //select * from [user] where [Uid] in(select uid from [user] where Phone=0 or Uid='' and pwd=111)
            string sql = string.Format("select * from [user] where uid= '{0}' and pwd='{1}' ",uid, pwd);
            return DBhelper.DataReader(sql);
        }
        public SqlDataReader dhdl(decimal phone,string pwd)
        {
            string sql = string.Format("select * from [user] where phone='{0}' and pwd='{1}'",phone,pwd);
            return DBhelper.DataReader(sql);
        }
    }
}
